﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QD.Snapshot.Core.Util
{
    public delegate void MyShowMessage(string msg);
    public delegate void ShowTextBox(TextBox text, string msg);

    public class EchoHelper
    {
        public static void ShowMessage(TextBox text, string msg)
        {
            try
            {
                if (text.InvokeRequired)
                {
                    ShowTextBox _myInvoke = new ShowTextBox(ShowMessage);
                    text.BeginInvoke(_myInvoke, new object[] { text, msg });
                }
                else
                {
                    if (text.Text.Length > 2000)
                        text.Text = text.Text.Substring(2000);
                    text.Text = msg + "\r\n" + text.Text;
                }
            }
            catch (Exception ex)
            {
                Pigeon.Utility.Log.Write(string.Format("{0}_{1}.log", "error", DateTime.Now.ToString("yyyyMMdd")), "ShowMessage错误:" + ex.ToString());
            }
        }
    }
}